package org.example.cet.demos.controller;

import org.example.cet.demos.domain.Result;
import org.example.cet.demos.service.impl.AnswerServiceImpl;
import org.example.cet.demos.service.impl.ScoreServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

@RestController
@RequestMapping("/score")
public class ScoreController {

    @Autowired
    private AnswerServiceImpl answerService;
    @GetMapping("/submitScore")
    public Result submitScore(@RequestParam("title") String title,
                              @RequestParam("bankId") String bankId,
                              @RequestParam("stuId") String stuId,
                              @RequestParam("qid") Integer qid,
                              @RequestParam("answer") String[] answer,
                              @RequestParam("homeworkId") Long homeworkId,
                              @RequestParam("type") Integer type,
                              @RequestParam("score") BigDecimal score){

        answerService.watscore(title,bankId, stuId, qid, answer, homeworkId, type, score);
        return Result.success();
    }

    @Autowired
    private ScoreServiceImpl scoreService;
    @PostMapping("/getOverPeopleSum")
    public Result getOverPeopleSum(Integer homeworkId){
        return Result.success(scoreService.getOverPeopleSum(homeworkId));
    }
    @PostMapping("/getAccuracy")
    public Result getAccuracy(Integer shomeworkId, Integer squestionId,Integer xquestionId,Integer questionId,Integer homeworkId){
        return Result.success(scoreService.getAccuracy(shomeworkId, squestionId,xquestionId, questionId,homeworkId));
    }
    @PostMapping("/getRightSum")
    public Result getRightSum(Integer xquestionId,Integer questionId,Integer homeworkId){
        return Result.success(scoreService.getRightSum(xquestionId,questionId,homeworkId));
    }
    @PostMapping("/getAverageScore")
    public Result getAverageScore(Integer qtype, Integer homeworkId, Integer type,String classId){
        return Result.success(scoreService.getAverageScore(qtype, homeworkId, type, classId));
    }
    @PostMapping("/getScore")
    public Result getScore(Integer homeworkId, String stuId){
        return Result.success(scoreService.getScore(homeworkId, stuId));
    }
    @PostMapping("/getRankPeopleSum")
    public Result getRankPeopleSum(Integer score1, Integer score2, Integer homeworkId,Integer type,String classId){
        return Result.success(scoreService.getRankPeopleSum(score1, score2, homeworkId, type, classId));
    }



}
